package com.example.myapplication.kotlin

// 类，对象的模版
class Car {
    var name: String = ""
    var price: Int = 0
    var speed: String = ""
    fun run() {
        println("嘟嘟嘟~")
    }
}

fun main() {
    // 对象.apply
    val car = Car().apply {
//        name = "保时捷"
//        price = 100000
//        speed = "300km"
//        run()
    }

//    println(car.name)
    // apply with

    // with
    with(car) {
        name = "小米yu7"
        price = 5000
        speed = "300km"
        run()
    }
    println(car.name)


    // run,局部作用域，先干嘛，就干嘛
    run {
        val car = Car()
        car.name = "某界X9"
        println(car.name)
    }

    // let
    val dreamCar: Car? = null
    dreamCar?.let {
        println("买到了")
        println(dreamCar.name)
    }

}